package com.xyht.sca_s.student_manage_system.modules.admissionInformation.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.admissionInformation.entity.req.SmsAdmissionInformationAddReq;
import com.xyht.sca_s.student_manage_system.modules.admissionInformation.entity.req.SmsAdmissionInformationDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.admissionInformation.entity.req.SmsAdmissionInformationUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.admissionInformation.service.SmsAdmissionInformationService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * <p>
 * 录取信息表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/admissionInformation")
@SecretBody
public class SmsAdmissionInformationController {


    @Resource
    private SmsAdmissionInformationService admissionInformationService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("批量导入录取信息")
    @PostMapping("/batch/add")
    public ResponseResult batchAddAdmissionInformation(@RequestBody Map<String,Object> map, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = admissionInformationService.batchAddAdmissionInformation(map,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiModelProperty("添加录取信息")
    @PostMapping("/add")
    public ResponseResult addAdmissionInformation(@RequestBody SmsAdmissionInformationAddReq addReq,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return admissionInformationService.addAdmissionInformation(addReq,userId);
    }

    @ApiModelProperty("删除录取信息")
    @PostMapping("/deleted")
    public ResponseResult deletedAdmissionInformation(@RequestBody SmsAdmissionInformationDeletedReq deletedReq){
        return admissionInformationService.deletedAdmissionInformation(deletedReq);
    }

    @ApiModelProperty("修改录取信息")
    @PostMapping("/update")
    public ResponseResult updateAdmissionInformation(@RequestBody SmsAdmissionInformationUpdateReq updateReq){
        return admissionInformationService.updateAdmissionInformation(updateReq);
    }


    @ApiModelProperty("查询录取信息详情")
    @GetMapping("/id")
    public ResponseResult getAdmissionInformationDetail(@RequestParam("id") String id){
        return admissionInformationService.getAdmissionInformationDetail(id);
    }

    @ApiModelProperty("查询录取信息列表")
    @GetMapping("/list")
    public ResponseResult getAdmissionInformationList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "admissionTime", required = false) String admissionTime,
                                                      @RequestParam(value = "searchStr", required = false) String searchStr) {
        return admissionInformationService.getAdmissionInformationList(pageNum,pageSize,searchStr,admissionTime);
    }

    @ApiModelProperty("查询自己的录取信息")
    @GetMapping("/getMyAdmissionInfo")
    @RequestPass
    public ResponseResult getMyAdmissionInfo(@RequestParam(value = "infoId") String infoId,
                                             @RequestParam(value = "code") String code,
                                             @RequestParam(value = "uid") String uid) {
        return admissionInformationService.getMyAdmissionInfo(infoId,code,uid);
    }


}

